﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ApprovalFlow.Models;

namespace ApprovalFlow.Interface
{
    public interface IWorkflowRepository
    {
        /// <summary>
        /// 创建一个新的工作流。
        /// </summary>
        /// <param name="workflow"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<string> CreateNewWorkflow(WorkflowInstance workflow, CancellationToken cancellationToken = default);

        /// <summary>
        /// 通过id获取工作流实例。
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<WorkflowInstance> GetWorkflowInstance(string Id, CancellationToken cancellationToken = default);

        /// <summary>
        /// 获取运行中的审批流实例的id。
        /// </summary>
        /// <param name="asAt">截至时间</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<IEnumerable<string>> GetRunnableInstances(DateTime asAt, CancellationToken cancellationToken = default);

        /// <summary>
        /// 通过提供id的集合获取工作流的列表。
        /// </summary>
        /// <param name="ids"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task<IEnumerable<WorkflowInstance>> GetWorkflowInstances(IEnumerable<string> ids, CancellationToken cancellationToken = default);

        /// <summary>
        /// 持久化工作流对象。
        /// </summary>
        /// <param name="workflow"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        Task PersistWorkflow(WorkflowInstance workflow, CancellationToken cancellationToken = default);

        /// <summary>
        /// 终止工作流的审批实例。
        /// </summary>
        /// <param name="workflowId"></param>
        /// <returns></returns>
        Task TerminateWorkflow(string workflowId);

        /// <summary>
        /// 删除工作流的审批实例。
        /// </summary>
        /// <param name="workflowId"></param>
        /// <returns></returns>
        Task DeleteWorkflow(string workflowId);
    }
}
